/**
 * @param {number[]} a
 * @return {number[]}
 */
var constructArr = function (a) {
  // 超时
  // let arr = []
  // for (let i = 0; i < a.length; i++) {
  //   let res = 1
  //   let j = (i + 1) % a.length
  //   for (let count=1; count < a.length; count++) {
  //     res *= a[j]
  //     j = (j + 1) % a.length
  //   }
  //   arr[i] = res
  // }

  let left = new Array(a.length)
  let right = new Array(a.length)
  let answer = new Array(a.length)
  left[0] =1
  for(let i=1;i<a.length;i++){
    left[i] = a[i-1]*left[i-1]
  }
  right[a.length-1] = 1
  for(let i=a.length-2;i>=0;i--){
    right[i] = a[i+1]*right[i+1]
  }

  for(let i=0;i<a.length;i++){
    answer[i] = left[i]*right[i]
  }

  return answer
}

constructArr([1, 2, 3, 4, 5])
